using System;
using System.Collections;
using System.Collections.Generic;
using Net.Messgae;

public class RoomInfo
{
    public static readonly int ROOM_USER_COUNT = 2; // 房间人数

    ulong _matchId;
    public ulong MatchId 
    {
        get { return _matchId; }
    }

    public uint Index
    {
        get { return GetIndex(); }
    }

    MessageNotifyGameStart _gameStartInfo = null;
    public MessageNotifyGameStart GameStartInfo 
    {
        get { return _gameStartInfo; }
    }

    public RoomInfo(ulong matchId)
    {
        _matchId = matchId;
    }

    List<MatchPlayerInfo> _players = new List<MatchPlayerInfo>();
    public List<MatchPlayerInfo> players
    {
        get { return _players; }
    }

    public bool CanReady()
    {
        return _players.Count >= ROOM_USER_COUNT;
    }

    public uint GetIndex()
    {
        foreach(var player in _players)
        {
            if(Model.Instance().playerModel.playerInfo.OpenId == player.OpenId)
            {   
                return player.Index;
            }
        }
        return 0;
    }

    public MatchPlayerInfo GetMeMatchInfo()
    {
        foreach(var player in _players)
        {
            if(Model.Instance().playerModel.playerInfo.OpenId == player.OpenId)
            {   
                return player;
            }
        }
        return null;
    }

    public int IndexOfPlayers(MatchPlayerInfo player)
    {
        for(int i = 0; i < _players.Count; i++)
        {
            if(player.OpenId == _players[i].OpenId)
            {
                return i;
            }
        }
        return -1;
    }

    public void OnGameStart(MessageNotifyGameStart gameStartInfo)
    {
        _gameStartInfo = gameStartInfo;
    }
}